<template>
    <div>
        <h1>管理员登录</h1>
        <table class="table table-bordered">
            <tbody>
                <tr>
                    <td align="right">用户名</td>
                    <td>
                        <input type="text" v-model="qureyInfo.username"/>
                    </td>
                </tr>
                <tr>
                    <td align="right">密码</td>
                    <td>
                        <input type="password" v-model="qureyInfo.password"/>
                    </td>
                </tr>
                <tr>
                    <td></td>
                    <td>
                        <input type="button" value="登录" class="btn btn-primary" @click="ok"/>
                    </td>
                </tr>
            </tbody>
        </table>

    </div>
</template>

<script setup lang="ts">
import axios from 'axios';
import { ref,reactive,onMounted } from 'vue';
import moment from 'moment';
import { useRoute,useRouter } from 'vue-router';

import {useCounterStore} from '@/stores/use'
const ac=useCounterStore();

//接收值
const route=useRoute();
//跳转页面
const router=useRouter();



let qureyInfo:any=reactive({
    username:'',
    password:''
})


//登录
const ok=()=>{
    if(qureyInfo.username=="")
    {
        alert("用户名不能为空");
        return;
    }
    if(qureyInfo.password=="")
    {
        alert("密码不能为空");
        return;
    }
    axios({
        url:'/api/Admin/AdminLoGin',
        method:'get',
        params:qureyInfo
    })
    .then(res=>{
        console.log(res);
        if(res.data==-1)
        {
            alert("用户名不存在");
            return;
        }
        if(res.data ==-2)
        {
            alert("密码错误");
            return;
        }
        
        alert("登录成功");
        ac.infor=res.data;
        router.push('/departmenAdd');
        return;
    })
    .catch(err=>{
        console.log(err);
        
    })

}






</script>

<style scoped>

</style>